﻿using DMSkin.Core;
using Dt261.ViewModel;
using Dt261.Views;
using Panuon.UI.Silver;
using Panuon.UI.Silver.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace Dt261
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow 
    {
       
        public MainWindow()
        {
            InitializeComponent();


            // this.WindowState = System.Windows.WindowState.Normal;//还原窗口（非最小化和最大化）
            // this.WindowStyle = System.Windows.WindowStyle.None; //仅工作区可见，不显示标题栏和边框


#if DEBUG
#else
                       this.ResizeMode = System.Windows.ResizeMode.CanMinimize;//不显示最大化和最小化按钮
           // this.Topmost = true;    //窗口在最前

            this.Left = 0.0;
            this.Top = 0.0;
            //全屏
            this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
            this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
#endif




            this.Closing += Window_Closing;
            //Frame.Navigate(new Page1());

            Broadcast.RegisterBroadcast<Page>("Navigation", (obj) =>
            {
                Frame.Navigate(obj);
            });

            Broadcast.RegisterBroadcast<string>("NavigationBack", (obj) =>
            {
                Frame.GoBack();
            });

    

            this.DataContext = new MainWindowViewModel();

        
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //MessageBoxResult result = MessageBox.Show("确定是退出吗？", "询问", MessageBoxButton.YesNo, MessageBoxImage.Question);


            var result = MessageBoxX.Show("确认退出？", "提醒", Application.Current.MainWindow, MessageBoxButton.YesNo, new MessageBoxXConfigurations()
            {
                MessageBoxStyle = MessageBoxStyle.Modern,
                MessageBoxIcon = MessageBoxIcon.Warning,
                ButtonBrush = "#F1C825".ToColor().ToBrush(),
            });

            if (result == MessageBoxResult.Yes)
            {

                MainWindowViewModel model = this.DataContext as MainWindowViewModel;
                model.OpenSP();//关闭串口
                e.Cancel = false;

            }


            //不关闭窗口
            if (result == MessageBoxResult.No)
                e.Cancel = true;
        }




        private void ComComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            MainWindowViewModel model = this.DataContext as MainWindowViewModel;

            model.OpenSP();
        }

        private void OpenCloseSP(object sender, RoutedEventArgs e)
        {
            MainWindowViewModel model = this.DataContext as MainWindowViewModel;

            model.OpenSP();
        }
    }


}
